﻿using System;
using System.Windows;

namespace RMBoink
{
    /// <summary>
    /// Interaction logic for Welcome.xaml
    /// </summary>
    public partial class Welcome : Window
    {
        public Welcome()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // Create OpenFileDialog
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

            // Set filter for file extension and default file extension
            dlg.DefaultExt = ".mp3";
            dlg.Filter = "Windows Audio Files (*.wav)|*.wav|MPEG Audio Files (*.mp3)|*.mp3";

            // Display OpenFileDialog by calling ShowDialog method
            Nullable<bool> result = dlg.ShowDialog();

            // Get the selected file name and display in a TextBox
            if (result == true)
            {
                // Open document
                string filename = dlg.FileName;
                SoundFile.Text = filename;
            }
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            var updatefloat = float.Parse(UpdateTime.Text);
            Properties.Settings.Default["Region"] = RegionBox.Text;
            Properties.Settings.Default["UpdateTime"] = updatefloat;
            Properties.Settings.Default["IsFirstRun"] = false;
            Properties.Settings.Default["Ignored"] = NationName.Text.Replace(" ", "_");
            if (SoundFile.Text != "custom sound file (optional)" && SoundFile.Text != null && SoundFile.Text != "")
            {
                Properties.Settings.Default["Sound"] = SoundFile.Text;
            }
            Properties.Settings.Default.Save(); // Saves settings in application configuration file
            System.Windows.Forms.Application.Restart();
            System.Windows.Application.Current.Shutdown();
        }
    }
}